// pages/shop/shop.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shopDesc: {
      name: "xxx专卖店",
      head_img: "https://tse1-mm.cn.bing.net/th/id/OIP-C.fR9s9Ys1hzRMIURSfhgBAwAAAA?pid=ImgDet&rs=1",
      background: "",
      authentication: "",
      star: 5
    },
    tabs: [{
        id: 0,
        value: "推荐",
        isActive: true
      },
      {
        id: 1,
        value: "全部",
        isActive: false
      },
    ],
    text: "",
    isSearch:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const {
      name
    } = this.data.shopDesc;
    wx.setNavigationBarTitle({
      title: name,
    });
  },
  //监听子组件触发的回调函数
  handleTabsItemChange(e) {
    // 获取被点击的标题索引
    const {
      index
    } = e.detail
    // 修改原数组 isActive 变为 true
    let {
      tabs
    } = this.data
    tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false)
    // 赋值
    this.setData({
      tabs
    })
  },
  // 取消搜索
  handleCancelSearch() {
    this.setData({
      text: "",
      isSearch: false,
      advice: []
    })
  },
  // 输入建议
  handleInputAdvice(e) {
    const text = e.detail.value.toString();
    let isSearch = false;
    if (text) isSearch = true;
    this.setData({
      text,
      isSearch
    });
  },

})